<?php
error_reporting(0);
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es" dir="ltr">
  <head>
    <title>PowerLaptops</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="default.css" />
    <link rel="stylesheet" type="text/css" href="ddlevelsfiles/ddlevelsmenu-base.css" />
    <link rel="stylesheet" type="text/css" href="ddlevelsfiles/ddlevelsmenu-topbar.css" />
    <link rel="stylesheet" type="text/css" href="ddlevelsfiles/ddlevelsmenu-sidebar.css" />
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="ddlevelsfiles/ddlevelsmenu.js">
    /***********************************************
    * All Levels Navigational Menu- (c) Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
    ***********************************************/
    </script>
  </head>
  <body>
    <noscript><p>Tu navegador no tiene activado javascript.</p></noscript>
    <div id="wrapper">
      <div id="header">
    		<div id = "publicidadLado">
          <img  src="images/static/contactenos_def.jpg" align="left"></img>
        </div>
        <img  src="images/static/envios_nacionales2.png" align="right"></img>
        <img src="images/static/pagos_seguros.png" align="right"></img>
        <div class="login">
          <br>
          <br>
          <?php
            if($_SESSION["autenticado"]!=1){
          ?>
          <div id="signin-c">
            <div type="button" id="boton_login">
              <a tabindex="3" class="signin" > <!-- href="/login" > -->
                <span>
                  Iniciar sesión
                </span>
              </a>
            </div>
            <div type="button" id="boton_register">
              <a tabindex="3" class="signin"> <!-- href="/login" > -->
                <span>
                  Registrate!
                </span>
              </a>
            </div>
          </div>
              <div id="signin_menu" class="signin_menu">
                <form name="iniciar" action="getUser.php" method="POST" enctype="multipart/form-data">
                    <div>
                      <label style="width: 77px;display:inline-block;">Correo:</label>
                    <input type="text" name="login" value="" size="10" />
                    <label> Password: </label>
                    <input type="password" name="pass" value="" size="10"/>
                  </div>
                  <span style="text-align:right;display:inline-block;"> 
                    <input type="button" value="acceder" name="registro"
                           onClick="javascript:comprueba2();">
                  </span>
                </form>
								<a href="recuperarClave.php">Olvidaste tu clave? </a>
                <script language="JavaScript" type="text/javascript">
                  function comprueba2(){
                  document.iniciar.submit();
                  }
                </script>
              </div>
              <script language="JavaScript" type="text/javascript">
                $("#signin_menu").hide();
                $("#boton_login").click(function() {
                $("#register_menu").hide();
                $("#signin_menu").toggle("slow");
                });
              </script>
              <div id="register_menu" class="register_menu">
								<a tabindex="3" onBlur="salio()" style="color: #000000" >
                <form name = "registroUsuario" action="insertUser2.php" method="POST">
                  <table border=0>
                    <tr><td>Nombre</td><td><input type="text" onkeypress="return noNumber(event)" onChange="verifNombre()" name="nombre" size="11" value="" ></td></tr>
                    <tr><td id="nombre" class="hid"></td><td class="exTel"></td></tr>
                    <tr class="" id="rapellido"><td>Apellido</td><td><input type="text" onChange="verifApellido()" onkeypress="return noNumber(event)" name="apellido" size="11" value=""</td></tr>
                    <tr><td id="apellido" class="hid"></td><td class="exTel"></td></tr>
                    <tr><td>C&eacute;dula o RIF
                          <select size="1" name="persona" onchange="swap()">
                            <option value="1">V</option>
                            <option value="0">J</option>
                          </select>
                        </td> <td>
                          <input type="text" onkeypress="return verifCI(event)" onChange="verifCITam()" name="ci" size="11" value=""
                        </td>
                    </tr>
                    <tr><td id="ci" class="hid"></td><td class="exTel"></td></tr>
                    <tr><td>Tel&eacute;fono</td><td><input type="text" onkeypress="return verifTel(event)" onchange="verifTelTam()"name="telefono" size="11" value=""</td></tr>
                    <tr><td id="telefono" class="hid">*Siga el ejemplo.</td><td class="exTel">Ej: 02125553344</td></tr>
                    <tr><td>Correo electr&oacute;nico</td>
                      <td><input type="text" onChange="verifCorreo()" name="correo" size="11" value=""</td></tr>
                    <tr><td id="correo" class="hid">*Correo incorrecto.</td><td class="exTel">Ej: correo@ejemplo.com</td></tr>
                    <tr><td>Contrase&ntilde;a</td><td><input type="password" name="contrasena" size="11" value=""</td></tr>
                    <tr><td>Repita contrase&ntilde;a</td><td><input type="password" onChange="verifDistintas()" name="repetida" size="11" value=""</td></tr>
                    <tr><td class="hid" id="clave">*Contraseñas distintas.</td><td></td></tr>
                  </table>
                  <center><input type="button" value="registrar" name="registrar" onClick="javascript:comprueba();"></center>
                  <input type="hidden" name="link" value="registroUsuario.php">
                </form>
								</a>
								<a href="" onClick="javascript:Show()" style="font-size: 9px ">No recuerdas tu contraseña?</a>
								<form name="recuperar_Contraseña" action="recuperar_Contraseña.php" method="POST">
								
								</form>
              </div>
            <script language="javascript">
              $("#register_menu").hide();
              $("#boton_register").click(function() {
              $("#signin_menu").hide();
              $("#register_menu").toggle("slow");
              });

							function salio(){
								alert("Salio");
							}

              function noNumber(evt){
                var key = evt.charCode;
                if ((65 <= key && key <= 90) || 
                     key ==241 ||
                     key == 32 ||
                     (97 <= key && key <= 122) ||
                     key == 0){
                  return true;
                }
                return false;
              }

              function swap(){
                if (document.registroUsuario.persona.value == 0){
                  document.getElementById('rapellido').setAttribute('style','visibility: hidden');
                  document.getElementById('apellido').setAttribute('style','visibility: hidden');
                }else{
                  document.getElementById('rapellido').setAttribute('style','visibility: visible');
                }
              }

              function verifTel(evt){
                var key = evt.charCode;
                if (key == 0)
                  return true;
                if (document.registroUsuario.telefono.value.length == 11)
                  return false;
                if ((48 <= key && key <= 57))
                  return true;
                return false;
              }

              function verifCITam(){
                if (document.registroUsuario.persona.value == 1 && document.registroUsuario.ci.value.length == 8)
                  document.getElementById("ci").setAttribute('style','visibility: hidden');
                else if (document.registroUsuario.persona.value == 0 && document.registroUsuario.ci.value.length == 9)
                  document.getElementById("ci").setAttribute('style','visibility: hidden');
                else
                  document.getElementById("ci").setAttribute('style','visibility: visible');
              }

              function verifCI(evt){
                var key = evt.charCode;
                if (key == 0)
                  return true;
                if (document.registroUsuario.persona.value == 1 && document.registroUsuario.ci.value.length == 8)
                  return false;
                if (document.registroUsuario.persona.value == 0 && document.registroUsuario.ci.value.length == 9)
                  return false;
                if (48 <= key && key <= 57){
                  return true;
                }
                return false;
              }

              function verifDistintas(){
                if (document.registroUsuario.contrasena.value != document.registroUsuario.repetida.value)
                  document.getElementById('clave').setAttribute('style','visibility: visible');
                else
                  document.getElementById('clave').setAttribute('style','visibility: hidden');
              }

              function verifTelTam(){
                if (document.registroUsuario.telefono.value.length < 11){
                  document.getElementById('telefono').innerHTML="*telefono incorrecto.";
                  document.getElementById('telefono').setAttribute('style','visibility: visible');
                }
                else{
                  document.getElementById('telefono').setAttribute('style','visibility: hidden');
                }
              }

              function verifCorreo(){
                var ExpRegCorreo = /^\w{3}([\.]*?[-]*?[_]*?\w+)*@\w{3}([\.-]?\w+)*(\.\w{2,4})+$/;
                if (!document.registroUsuario.correo.value.match(ExpRegCorreo)){
                  document.getElementById('correo').setAttribute('style','visibility: visible');
                  document.getElementById('correo').innerHTML="*correo incorrecto.";
                }
                else{
                  document.getElementById('correo').setAttribute('style','visibility: hidden');
                }
              }

              function verifApellido(){
                var ExpRegNombre = /^[a-zA-Z]*([ ]{0,1}[a-zA-Z])*$/;
                var vacio =/^$/;
                if (!document.registroUsuario.apellido.value.match(ExpRegNombre) &&
                    !document.registroUsuario.apellido.value.match(vacio) ){
                  document.getElementById('apellido').setAttribute('style','visibility: visible');
                }
                else{
                  document.getElementById('apellido').setAttribute('style','visibility: hidden');
                }
              }


              function verifNombre(){
                var ExpRegNombre = /^[a-zA-Z]*([ ]{0,1}[a-zA-Z])*$/;
                var vacio =/^$/;
                if (!document.registroUsuario.nombre.value.match(ExpRegNombre) &&
                    !document.registroUsuario.nombre.value.match(vacio) ){
                  document.getElementById('nombre').setAttribute('style','visibility: visible');
                }
                else{
                  document.getElementById('nombre').setAttribute('style','visibility: hidden');
                }
              }

              function comprueba(){
                var ExpRegCorreo = /^\w{3}([\.]*?[-]*?[_]*?\w+)*@\w{3}([\.-]?\w+)*(\.\w{2,4})+$/;
                cor = true;
                if(document.forms.registroUsuario.contrasena.value != document.forms.registroUsuario.repetida.value){
                  document.getElementById('clave').setAttribute('style','visibility: visible');
                  document.getElementById('clave').innerHTML="*contraseñas distintas.";
                  cor = false;
                }
                if (document.forms.registroUsuario.contrasena.value == ""){
                  document.getElementById('clave').setAttribute('style','visibility: visible');
                  document.getElementById('clave').innerHTML="*introducir una contraseña.";
                  cor = false;
                }
                if (document.forms.registroUsuario.contrasena.value.length < 5){
                  document.getElementById('clave').setAttribute('style','visibility: visible');
                  document.getElementById('clave').innerHTML="*la contrasena debe tener al menos 5 caracteres.";
                  cor = false;
                }
                if (document.forms.registroUsuario.correo.value == ""){
                  document.getElementById('correo').innerHTML="*introducir un correo.";
                  document.getElementById('correo').setAttribute('style','visibility: visible');
                  cor = false;
                }
                else if (!document.forms.registroUsuario.correo.value.match(ExpRegCorreo)){
                  document.getElementById('correo').innerHTML="*correo incorrecto.";
                  document.getElementById('correo').setAttribute('style','visibility: visible');
                  cor = false;
                }else{
                  document.getElementById('correo').setAttribute('style','visibility: hidden');
                }
                if (document.forms.registroUsuario.nombre.value == ""){
                  document.getElementById('nombre').innerHTML="*introducir un nombre.";
                  document.getElementById('nombre').setAttribute('style','visibility: visible');
                  cor = false;
                }else{
                  document.getElementById('nombre').setAttribute('style','visibility: hidden');
                }
                if (document.forms.registroUsuario.ci.value == ""){
                  document.getElementById('ci').innerHTML="*introducir una CI o RIF.";
                  document.getElementById('ci').setAttribute('style','visibility: visible');
                  cor = false;
                }else{
                  document.getElementById('ci').setAttribute('style','visibility: hidden');
                }
                if (document.registroUsuario.persona.value == 1){
                  if (document.forms.registroUsuario.apellido.value == ""){
                    document.getElementById('apellido').innerHTML="*introducir un apellido.";
                    document.getElementById('apellido').setAttribute('style','visibility: visible');
                    cor = false;
                  }else{
                    document.getElementById('apellido').setAttribute('style','visibility: hidden');
                  }
                }
                if (document.registroUsuario.ci.value.length <= 6){
                  document.getElementById('ci').innerHTML="*cedula invalida.";
                  document.getElementById('ci').setAttribute('style','visibility: visible');
                  cor = false;
                }
                if (document.forms.registroUsuario.telefono.value.length != 11){
                  document.getElementById('telefono').innerHTML="*introducir telefono valido.";
                  document.getElementById('telefono').setAttribute('style','visibility: visible');
                  cor = false;
                }
                else{
                  find = false;
                  cod = document.registroUsuario.telefono.value.substring(0,4);
                  lcod = new Array("0414","0412","0416","0424","0426","0212","0248","0281","0283","0282","0285","0292","0240","0247","0277","0278","0243","0244","0246","0273","0278","0284","0285","0286","0288","0289","0241","0242","0243","0245","0249","0258","0287","0259","0268","0269","0279","0235","0238","0246","0247","0251","0252","0253","0271","0274","0275","0234","0239","0291","0292","0287","0295","0255","0256","0257","0272","0293","0294","0275","0276","0277","0271","0272","0253","0254","0261","0262","0263","0264","0265","0266","0271");
                  for(i = 0 ; i <lcod.length && !find;i++){
                    if (lcod[i] == cod){
                      find = true;
                    }
                  }
                  if (!find){
                    document.getElementById('telefono').setAttribute('style','visibility: visible');
                    document.getElementById('telefono').innerHTML="*codigo de area invalido.";
                    cor = false;
                  }
                }
                if (cor)
                  document.registroUsuario.submit();
              }
            </script>
            <?php
              } else{
                echo "<h5>".$_SESSION["nombreusr"]." <a href=\"logout.php\">salir</a></h5>";
                echo "<a href=\"PanelUsuario.php\">Panel de Control</a>";
              }
            ?>
          </div>
	      </div>
      <div id="menu">
      	<div id = "logo">
          <img src="images/logo2.jpg" align="left" width = 225 height = 50></img>
        </div>
      	<div id = "barra">
	        <br>
          <br>
          <table>
            <td>
              <a href="index.php" >Inicio</a>
            </td>
            <td>
              <a href="catalogo.php">Cat&aacute;logo</a>
            </td>
            <?php if($_SESSION["tipo"]==1){?>
              <td>
                <a href="editarSimple.php">Edici&oacute;n de Productos </a>
              </td>
              <td>
                <a href="admin.php">Administraci&oacute;n</a>
              </td>
            <? }else if ($_SESSION["autenticado"]==1){?>
            <?} ?>
          </table>
      	</div>
      </div>
